package my.mybatis.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.ToString;

import java.io.Serializable;

@ToString
@ApiModel(description = "排序参数对象")
public class OrderParam implements Serializable{
	private static final long serialVersionUID = -4954555024786344375L;

	// 多字段排序时候用
	private static final int DEFAULT_ORDER_INDEX = 1;
	// 升序
	public static final String ORDER_ASC = "ASC";
	// 降序
	public static final String ORDER_DESC = "DESC";

	@ApiModelProperty(value = "字段属性（非数据库字段）")
	private String orderBy;
	@ApiModelProperty(value = "排序类型（ASC/DESC）")
	private String ascOrDesc = ORDER_ASC;
	// 排序字段的orderBy 的顺序
	private int orderIndex=DEFAULT_ORDER_INDEX;

	public static class Builder{
		private String orderBy;
		private String ascOrDesc = ORDER_ASC;
		private int orderIndex = DEFAULT_ORDER_INDEX;

		public Builder(){}

		public Builder orderBy(String orderBy)
		{
			this.orderBy = orderBy;
			return this;
		}
		public Builder ascOrDesc(String ascOrDesc)
		{
			this.ascOrDesc = ascOrDesc;
			return this;
		}
		public Builder orderIndex(int orderIndex)
		{
			this.orderIndex = orderIndex;
			return this;
		}

		public OrderParam build()
		{
			return new OrderParam(this);
		}
	}

	private OrderParam(Builder builder)
	{
		this.orderBy = builder.orderBy;
		this.ascOrDesc = builder.ascOrDesc;
		this.orderIndex = builder.orderIndex;
	}

	public OrderParam(){}
	public OrderParam(String field,String order,int orderIndex){
		this.ascOrDesc = order;
		this.orderBy = field;
		this.orderIndex = orderIndex;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public String getAscOrDesc() {
		return ascOrDesc;
	}

	public void setAscOrDesc(String ascOrDesc) {
		this.ascOrDesc = ascOrDesc;
	}

	public int getOrderIndex() {
		return orderIndex;
	}

	public void setOrderIndex(int orderIndex) {
		this.orderIndex = orderIndex;
	}
}
